package com.atguigui.leetcode;

/**
 * 1413.逐步求和得到正数的最小值
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/8/9 8:48
 */
public class P1413MinimumValueToGetPositiveStepByStepSum {
    public static void main(String[] args) {
        Solution solution = new P1413MinimumValueToGetPositiveStepByStepSum().new Solution();
        // TO TEST
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int minStartValue(int[] nums) {
            int accSum = 0, accSumMin = 0;
            for (int num : nums) {
                //累加求合
                accSum += num;
                //取最小的
                accSumMin = Math.min(accSumMin, accSum);
            }
            return -accSumMin + 1;
        }
    }
}
